#define _CRT_SECURE_NO_WARNINGS 1
class Solution {
public:
    vector<vector<int>> ret;
    vector<int> path;
    bool check[9];
    void bfs(vector<int>& nums) {
        if (path.size() == nums.size()) {
            if (find(ret.begin(), ret.end(), path) == ret.end())
                ret.push_back(path);
            return;
        }
        for (int i = 0; i < nums.size(); i++)
        {
            if (check[i] == false)
            {
                path.push_back(nums[i]);
                check[i] = true;
                bfs(nums);
                path.pop_back();
                check[i] = false;
            }
        }
    }
    vector<vector<int>> permuteUnique(vector<int>& nums) {
        bfs(nums);
        return ret;
    }
};